package com.wawayaya.service.download;


import android.content.Context;
import android.content.Intent;
import android.os.Binder;

import com.wawayaya.bean.Books;
import com.wawayaya.bean.Download;
import com.wawayaya.util.TLog;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicBoolean;


public class BookItemVessel extends Binder {

	private Context m_ct = null;

	private  static BookItemVessel  itemVessel= null;

	public static BookItemVessel getInstance(Context context) {
		if(null==itemVessel){
			itemVessel = new BookItemVessel(context);
		}
		return  itemVessel;
	}

	public BookItemVessel(Context context){

	}
	private LinkedList<Download> tasks= new LinkedList<>();

	public LinkedList<Download> getTasks() {
		return tasks;
	}

   public void  addDoloadTask(final Books books){
	  /*
	   for(int i = 0; i < books.getPartArray().length(); i++) {
		   TLog.log("BookItemVessel add task");   //http://wawa-qin.b0.upaiyun.com   http://10.135.195.180:8086
		   final Download  download = new Download(ibooknetid,ibookorigid);
		   books.setZipCurrent(i);

		   download.downloadTask = new DownloadTask(m_ct);
		   download.book = books;
		   tasks.add(download);
	   }*/
   }

	public void clear( ) {
		if(null != tasks && tasks.size()>0){
			try{
				Iterator<Download> iter = tasks.iterator();
				while (iter.hasNext()) {
					Download mdpi = iter.next();
					if(null != mdpi) {
						mdpi.downloadTask.clear();
						mdpi.downloadTask.cancel(true);
						iter.remove();
					}
				}
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		if(null!=tasks && tasks.size()>0){
			tasks.clear();
		}
	}

}
